import * as types from '../mutation-types'

const state = {
  baseBrandList: [],
  baseBrandRecommend: [],
  baseCategoryList: [],
  baseCategoryRecommend: [],
  baseHomeFlash: [],
  baseHomeSubjects: [],
  baseProductHot: [],
  baseHotSearchKey: {},
  baseHomeShopStreet: [],
  mallBrandList: [],
  baseValue: {},
  wxShareData: {},
  shareData:{
    shoeShareData:{}
  }
}


const getters = {
  brands: state => state.baseBrandList,
  brandRecommeds: state => state.baseBrandRecommend,
  categorys: state => state.baseCategoryList,
  categoryRecommeds: state => state.baseCategoryRecommend,
  homeFlash: state => state.baseHomeFlash,
  homeSubjects: state => state.baseHomeSubjects,
  hotSearchKey: state => state.baseHotSearchKey,
  mallBrands: state => state.mallBrandList,
  productRecommends: state => state.baseProductHot,
  homeShopStreet: state => state.baseHomeShopStreet,
  baseValue: state => state.baseValue,
  wxShareData: state => state.wxShareData,
  shoeShareData:state=>state.shareData.shoeShareData
}

const actions = {
  setBaseBrand({ commit, state }, payload) {
    commit(types.BASE_BRAND_LIST, payload);
  },
  setHotSearchKey({ commit, state }, payload) {
    commit(types.BASE_HOT_SEARCH_KEY, payload);
  },
  setMallBrandLists({ commit, state }, payload) {
    commit(types.MALL_BRAND_LIST, payload);
  },
  setHomeGather({ commit, state }, payload) {
    commit(types.BASE_HOME_GATHER, payload);
  },
  setBaseValue({ commit, state }, payload) {
    commit(types.BASE_VALUE, payload)
  },
  setWxShareData({ commit, state }, payload) {
    commit(types.BASE_WXSHARE_DATA, payload)
  },
}

const mutations = {
  [types.BASE_BRAND_LIST](state, payload) {
    state.baseBrandList = payload;
  },
  [types.BASE_HOT_SEARCH_KEY](state, payload) {
    state.baseHotSearchKey = payload;
  },
  [types.MALL_BRAND_LIST](state, payload) {
    state.mallBrandList = payload;
  },
  [types.BASE_HOME_GATHER](state, payload) {
    state.baseBrandRecommend = payload.hotbrand;
    state.baseCategoryRecommend = payload.hotcategory;
    state.baseHomeFlash = payload.flash;
    state.baseHomeSubjects = payload.subject;
    state.baseProductHot = payload.hotproducts;
    state.baseHomeShopStreet = payload.shopstreet;
  },
  [types.BASE_VALUE](state, payload) {
    state.baseValue = payload;
  },
  [types.BASE_WXSHARE_DATA](state, payload) {
    state.wxShareData.appId = payload.appId;
    state.wxShareData[payload.link] = {
      timestamp: payload.timestamp,
      nonceStr: payload.nonceStr,
      signature: payload.signature,
    }
  },
}

export default { state, getters, actions, mutations }